/**
 * 
 */
package clids.ex2.filters;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Li0r
 *
 */

public class BeforeFilter extends AbstractFilter {

	private static final String DATE_FORMAT = "dd/MM/yyyy";
	protected static final int MULTIPLIER = 1000;
	private Date beforeDate = null;
			
	public BeforeFilter(String params) {
		super(params);
		SimpleDateFormat a = new SimpleDateFormat(DATE_FORMAT);
		
		try {
			beforeDate = a.parse(parameters[0]);
		} catch (ParseException e) {
			System.out.println("parse error of file");
			// TODO Auto-generated catch block
			
		}
	}

	@Override
	public boolean isValid(String file) {
		
		File fileData = new File(file);
		Date fileLastModified = new Date(fileData.lastModified() * MULTIPLIER);
		if( fileLastModified.before(beforeDate)){
			return true;
		}
		return false;
	}

}